package cn.gzsxt.music.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gzsxt.music.query.SingerQueryObject;
import cn.gzsxt.music.service.SingerService;
import cn.gzsxt.music.vo.MsgObj;

@Controller
@Scope("request")
@RequestMapping("/singer")
public class SingerController {
	
	@Autowired
	private SingerService service;
	
	
	@RequestMapping("singerPage")
	public String singerPage() {
		
		return "singerPage";
	}
	
	@RequestMapping("singerList")
	@ResponseBody
	public Map<String, Object> singerList(SingerQueryObject qo) {
				
		Map<String, Object> result = service.selectSingerDataByCondition(qo);
		return result;		
	}
				
	@RequestMapping("addSinger")
	@ResponseBody
	public MsgObj addSinger(@RequestParam Map<String,Object> params) {
		int row = service.saveSinger(params);
		
		MsgObj msgObj = new MsgObj(0, "添加歌手失败");
		if (row == 1) {
			msgObj = new MsgObj(1, "添加歌手成功");
		} else if(row == 2 ) {
			msgObj = new MsgObj(0, "此歌手已经存在");
		}		
		return msgObj;		
	}
	
	@RequestMapping("updateSinger")
	@ResponseBody
	public MsgObj updateSinger(@RequestParam Map<String, Object> params) {
		
		int row = service.updateSinger(params);
		
		MsgObj msgObj = new MsgObj(0, "修改歌手失败");
		if(row == 1) {
			msgObj = new MsgObj(1, "修改歌手成功");
		}else if(row == 2) {
			msgObj = new MsgObj(0, "此歌手已经存在");
		}
		return msgObj;
	}
	
	@RequestMapping("deleteSingerById")
	@ResponseBody
	public MsgObj deleteSingerById(Long singer_id) {
		
		int row = service.deleteSingerById(singer_id);
		
		MsgObj msgObj = new MsgObj(0, "删除歌手失败");
		if(row == 1) {
			msgObj = new MsgObj(1, "删除歌手成功");
		}
		return msgObj;
	}
			
	
}
